package com.txunda.zhuohired.fgt.user;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ants.theantsgo.gson.GsonUtil;
import com.bumptech.glide.Glide;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.aty.user.my.ApplyShareAty;
import com.txunda.zhuohired.aty.user.my.CareerProgressAty;
import com.txunda.zhuohired.aty.user.my.GeneralizeAty;
import com.txunda.zhuohired.aty.user.my.HomeLocationAty;
import com.txunda.zhuohired.aty.user.my.MyCollectAty;
import com.txunda.zhuohired.aty.user.my.MyPriceAty;
import com.txunda.zhuohired.aty.user.my.SettingAty;
import com.txunda.zhuohired.aty.user.resume.PurposeAty;
import com.txunda.zhuohired.base.BaseFgt;
import com.txunda.zhuohired.bean.user.my.MyBean;
import com.txunda.zhuohired.http.pst.InfoPst;

import cn.gavinliu.android.lib.shapedimageview.ShapedImageView;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/2/26 14:57
 * 功能描述：我的
 * 联系方式：jiahuanchen@126.com
 */

public class MyFgt extends BaseFgt {
    /**
     * 返回
     */
    @ViewInject(R.id.iv_layout_blue_back)
    private ImageView iv_layout_blue_back;
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_blue_center)
    private TextView tv_layout_blue_center;
    /**
     * 头像
     */
    @ViewInject(R.id.iv_my_head)
    private ShapedImageView iv_my_head;
    /**
     * 名称
     */
    @ViewInject(R.id.tv_my_name)
    private TextView tv_my_name;
    /**
     * 自我评价
     */
    @ViewInject(R.id.tv_my_self)
    private TextView tv_my_self;

    private String token = "";
    private InfoPst infoPst;

    @Override
    @OnClick({R.id.tv_my_collect, R.id.tv_my_purpose, R.id.tv_my_price, R.id.tv_my_home_location, R.id
            .tv_my_career_progress, R.id.tv_my_generalize, R.id.tv_my_setting, R.id.tv_my_share})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_my_collect://我的收藏
                startActivity(MyCollectAty.class, null);
                break;
            case R.id.tv_my_purpose://求职意向
                startActivity(PurposeAty.class, null);
                break;
            case R.id.tv_my_price://我的钱包
                startActivity(MyPriceAty.class, null);
                break;
            case R.id.tv_my_home_location://家的位置
                startActivity(HomeLocationAty.class, null);
                break;
            case R.id.tv_my_career_progress://求职进展
                startActivity(CareerProgressAty.class, null);
                break;
            case R.id.tv_my_generalize://推广好友
                startActivity(GeneralizeAty.class, null);
                break;
            case R.id.tv_my_setting://设置
                startActivity(SettingAty.class, null);
                break;
            case R.id.tv_my_share://求职分享
                startActivity(ApplyShareAty.class, null);
                break;
        }
    }

    @Override
    protected void immersionInit() {
        showStatusBar(R.id.layout_blue_head);
        iv_layout_blue_back.setVisibility(View.GONE);
        tv_layout_blue_center.setText("我的");
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fgt_my;
    }

    /**
     * 当Fragment显示是运行该方法
     *
     * @param hidden
     */
    @Override
    public void onHiddenChanged(boolean hidden) {

        if (hidden) {
            //界面不可见
        } else {
            // 界面可见
            initHttp();
        }
    }

    private void initHttp() {
        infoPst.infoHome(token);
    }

    @Override
    protected void initialized() {
        token = application.getUserInfo().get("data");
        infoPst = new InfoPst(this);
    }

    @Override
    protected void requestData() {

    }

    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        if (requestUrl.contains("infoHome")) {
            //            L.e("==========infoHome==========", jsonStr);
            MyBean myBean = GsonUtil.GsonToBean(jsonStr, MyBean.class);
            Glide.with(getActivity()).load(myBean.getData().getImg()).error(R.mipmap.icon_defult).placeholder(R
                    .mipmap.icon_defult).dontAnimate().into(iv_my_head);
            if (TextUtils.isEmpty(myBean.getData().getName())) {
                tv_my_name.setVisibility(View.GONE);
            } else {
                tv_my_name.setVisibility(View.VISIBLE);
                tv_my_name.setText(myBean.getData().getName());
            }
            if (TextUtils.isEmpty(myBean.getData().getSelf_speak())) {
                tv_my_self.setVisibility(View.GONE);
            } else {
                tv_my_self.setVisibility(View.VISIBLE);
                tv_my_self.setText(myBean.getData().getSelf_speak());
            }
            return;
        }
    }
}
